import request from '@/axios'
import {
  SysConfigurationDetailVo,
  SysConfigurationEditQo,
  SysConfigurationListVo,
  SysConfigurationSearchQo
} from './types'
import { BaseDeleteQo } from '@/base/api/BaseQo'
import { KeyLabelValueVo } from '@/base/api/KeyLabelValueVo'
import { ImportQo } from '@/base/api/ImportQo'

export const sysConfigurationPageApi = (
  data: SysConfigurationSearchQo
): Promise<IResponse<Array<SysConfigurationListVo>>> => {
  return request.post({ url: '/sysConfiguration/page.adw', data })
}

export const sysConfigurationDetailApi = (
  id: number
): Promise<IResponse<SysConfigurationDetailVo>> => {
  const data = { id }
  return request.post({
    url: '/sysConfiguration/detail.adw',
    data
  })
}

export const sysConfigurationAddApi = (
  data: SysConfigurationEditQo
): Promise<IResponse<number>> => {
  return request.post({ url: '/sysConfiguration/add.adw', data })
}

export const sysConfigurationUpdateApi = (
  data: SysConfigurationEditQo
): Promise<IResponse<void>> => {
  return request.post({ url: '/sysConfiguration/update.adw', data })
}

export const sysConfigurationDeleteApi = (data: BaseDeleteQo): Promise<IResponse<void>> => {
  return request.post({ url: '/sysConfiguration/delete.adw', data })
}

export const sysConfigurationAllConfigApi = (
  data: SysConfigurationSearchQo
): Promise<IResponse<Array<any>>> => {
  return request.post({ url: '/sysConfiguration/allConfig.adw', data })
}

export const sysConfigurationExportApi = (
  data: SysConfigurationSearchQo
): Promise<IResponse<void>> => {
  return request.post({ url: '/sysConfiguration/export.adw', data })
}

export const sysConfigurationImportApi = (data: ImportQo): Promise<IResponse<void>> => {
  const formData = new FormData()
  formData.append('moduleName', data.moduleName)
  formData.append('taskName', data.taskName)

  // 添加所有文件
  data.files.forEach((file) => {
    formData.append('files', file)
  })

  return request.post({
    url: '/sysConfiguration/import.adw',
    data,
    headers: { 'Content-Type': 'multipart/form-data' }
  })
}

// [[ OnflowGenerator Range (- selectFunctions -) Start ]]
export const selectSysConfigurationConfigKeyListApi = (
  data: SysConfigurationSearchQo
): Promise<IResponse<Array<KeyLabelValueVo>>> => {
  return request.post({ url: '/sysConfiguration/selectConfigKeyList.adw', data })
}
// [[ OnflowGenerator Range (- selectFunctions -) End ]]
